package ru.jexp.rcp.supply.viewer;

import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class JExpContentProvider implements IStructuredContentProvider {

	private ListenerList listeners = new ListenerList();

	@Override
	public Object[] getElements(Object inputElement) {
		return ArrayContentProvider.getInstance().getElements(inputElement);
	}

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		notifyInputChangeListener();
	}

	public void addInputChangeListener(JExpInputChangeListener listener) {
		listeners.add(listener);
	}

	public void removeInputChangeListener(JExpInputChangeListener listener) {
		listeners.remove(listener);
	}

	public void notifyInputChangeListener() {
		Object[] copyListeners = listeners.getListeners();
		for (Object object : copyListeners) {
			JExpInputChangeListener listener = (JExpInputChangeListener) object;
			listener.change();
		}

	}
}
